<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%--<c:set var="ctx" value="${pageContext.request.contextPath}"/>--%>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>委外催收回款流程附加页面</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <form id="cltAuth">
            <div class="fieldset1 tabel_col clearFix">
                <div class="caption">
                    <span class="title">基本信息</span>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">申请人</div>
                    <div class="field">
                        <span id="authOrg" name="authOrg">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">申请日期</div>
                    <div class="field">
                        <span id="applyDt" name="applyDt">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <span id="cstNm" name="cstNm">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <span id="paySchNo" name="paySchNo">&nbsp;</span>
                    </div>
                </div>
                <div class="caption">
                    <span class="title">委案信息</span>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">委案金额</div>
                    <div class="field">
                        <span id="authAmt" name="authAmt">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">逾期天数</div>
                    <div class="field">
                        <span id="ovdDay" name="ovdDay">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">委案日期</div>
                    <div class="field">
                        <span id="startDate" name="startDate">&nbsp;</span>
                    </div>
                </div>
                <div class="caption">
                    <span class="title">回款信息</span>
                </div>
                <div class="fieldset1 tabel_col clearFix">
                    <div class="fieldBox col_50">
                        <div class="label">打款人</div>
                        <div class="field">
                            <input type="text" id="payer" name="payer" class="ui-textbox" value=""
                                   validate="{required:true}"/>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50 payDt">
                        <div class="label">打款日期</div>
                        <div class="field">
                            <input name="payDt" id="payDt" type="text" class="ui-datepicker" value=""
                                   validate="{required:true}">
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50 recoveryAmt">
                        <div class="label">打款金额</div>
                        <div class="field">
                            <input type="text" id="recoveryAmt" name="recoveryAmt" class="ui-textbox" value=""
                                   validate="{required:true}"/>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50 payWay">
                        <div class="label">来款方式</div>
                        <div class="field">
                            <input name="payWay" id="payWay" data-value=" " placeholder="--请选择--" ltype="combobox" validate="{required:true}">
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50 isStlAmt">
                        <div class="label">是否为结清款</div>
                        <div class="field">
                            <select name="isStlAmt" id="isStlAmt" onchange="checkIsStlAmt()">
                                <option value="  " seleted>请选择</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50 isResolve">
                        <div class="label">是否分解</div>
                        <div class="field">
                            <select name="isResolve" id="isResolve">
                                <option value="  " seleted>请选择</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>
                </div>
                <!-- 上传附件 -->
                <div class="fieldset1 tabel_col clearFix">
                    <div class="fieldBox col_100 uploadFileDiv">
                        <div class="label">附件上传</div>
                        <div class="field">
                            <jsp:include page="../commFilesUpload.jsp" flush="true" >
                                <jsp:param name="filePath" value="cltAuth"/>
                            </jsp:include>
                            <div id="fileUpload1" class="upfileBoxs"></div>
                            <span class="sq-button sq-button-hasicon" id="btnUpload1" onclick="ajaxFileUploadImg('uploads1',1)">
										<i class="sqBtnIco_9"></i>上传
									</span>
                        </div>
                    </div>
                    <!-- 附件显示 -->
                    <div class="fieldBox col_100">
                        <span class="btns"><span class="sq-button sq-button-round" onclick="downloadFileByUrl();">打包下载</span></span>
                        <div style="width: 98%; margin-left: 1%;">
                            <jsp:include page="../commFilesList.jsp" flush="true" ></jsp:include>
                            <div id="ligergrid_file1" class="sq-grid"></div>
                        </div>
                    </div>
                </div>
                <div class="btnsBox col_100 saveDiv" style="text-align: center;">
                    <span id="saveBtn" class="sq-button sq-button-round" onclick="save();">保存</span>
                </div>
                <div class="fieldBox col_100" style="display:none;">
                    <div class="field">
                        <input name="uploadUsr" id="uploadUsr" type="text" class="ui-textbox" value="${uploadUsr}">
                        <input name="delFlag" id="delFlag" type="text" class="ui-textbox" value="">
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    var applyId = '${applyId}';
    var taskFlag = '${taskFlag}';
    var viewFlag = '${viewFlag}';

    $(function () {
        var formSet1 = $("#cltAuth").ligerForm({
            validate: true
        });
        if ("2" == taskFlag) {
            liger.get("delFlag").setValue("1");
        }
        initData(applyId);
        // 委案催收资料Grid
        var _url = '<%=path%>/clt/auth/flow/initFilesList.do';
        var tabNm = 'RSK_CLT_AUTH_RCV_APL';
        loadFilesLiger(1, applyId,_url,tabNm);
        // 设置页面可编辑项
        showOrEdit();
        $("#payWay").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("payWay").setData(${payWays});
    });

    // 初始化页面数据
    function initData(applyId) {
        var url = "<%=path%>/clt/auth/flow/initCollectionData.do";
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {applyId: applyId},
            url: url,
            success: function (msg) {
                if (msg.success == 1) {
                    // 设置页面展示数据
                    setData(msg.data);
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function setData(data) {
        var form = liger.get("cltAuth");
        form.setData({
            payer: data.payer,
            payDt: data.payDt,
            recoveryAmt: data.recoveryAmt
        });
        $("#applyDt").html(renderDate(data.crtTm));
        $("#authOrg").html(data.authOrgCd);
        $("#cstNm").html(data.cstNm);
        $("#paySchNo").html(data.paySchNo);
        $("#authAmt").html(data.authAmt);
        $("#ovdDay").html(data.ovdDay);
        $("#startDate").html(renderDate(data.authDt));
        if (data.payWay) {
            liger.get("payWay").setValue(data.payWay);
        }
        if (null != data.isStlAmt) {
            liger.get("isStlAmt").setValue(data.isStlAmt);
        }
        if (null != data.isResolve) {
            liger.get("isResolve").setValue(data.isResolve);
        }
        if ("1" == data.isStlAmt) {
            liger.get("isResolve").setDisabled();
        }
    }

    function uploadFileByUrl(_url, _name) {
        if (SQ.regs.img.test(_name)) {
            //SQ.imgPreview(_url);
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '委外催收资料', 'location=yes, width=800, height=600');
        } else {
            window.open(_url);
        }
    }

    // 格式化时间
    function renderDate(dateStr1) {
        var dateStr2 = "";
        if(null != dateStr1){
            var date = new Date(dateStr1);
            dateStr2 = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr2;
    }

    function checkIsStlAmt () {
        var isStlAmt = $("#isStlAmt").val();
        if ("1" == isStlAmt) {
            liger.get("isResolve").setValue("  ");
            liger.get("isResolve").setDisabled();
        } else if ("0" == isStlAmt) {
            liger.get("isResolve").setEnabled();
        }
    }

    // 保存文件后保存信息
    function save() {
        var form = liger.get("cltAuth");
        if (!form.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false;
        }
        if ("1" == taskFlag) {
            // 渠道专员审批
        var isStlAmt = $("#isStlAmt").val();
        if ("" == isStlAmt.trim() || null == isStlAmt.trim()) {
            $.ligerDialog.SQalert({content: "请选择是否为结清款", SQ_type: "warning"});
            return false;
        } else if ("0" == isStlAmt) {
            var isResolve = $("#isResolve").val();
            if ("" == isResolve.trim() || null == isResolve.trim()) {
                $.ligerDialog.SQalert({content: "请选择是否分解", SQ_type: "warning"});
                return false;
            }
        }
        }
        var fileArray = JSON.stringify(getUploadResultParams(1));
        var url = "<%=path%>/clt/auth/flow/uploadAttchment.do";
        if (null == fileArray) {
            return false;
        } else {
            if (applyId) {
                var data = {
                    "docArray": fileArray,
                    "pkId": applyId,
                };
                AjaxUtils.ajaxPost(url, data, function (msg) {
                    if (msg.success == 1) {
                        if (msg.data) {
                            //刷新附件页面GRID方法和清空上传按钮
                            refreshUlFileRecList(1);
                            clearUploadResultParams(1);
                        }
                        var form = liger.get("cltAuth");
                        if (!form.valid()) {
                            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                            return false; //验证不通过，不执行以下代码
                        }
                        var data = form.getData();
                        data['applyId'] = applyId;
                        var url = '<%=path%>/clt/auth/flow/modify4CltAuthFlow.do';
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            data: data,
                            url: url,
                            success: function (msg) {
                                if (msg.success == 1) {
                                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                                    // parent.grid.reload();
                                } else {
                                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                                }
                            }
                        });
                    } else {
                        UIUtils.alertError(msg.info);
                    }
                }, true);
            } else {
                $.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！", SQ_type: "error"});
            }
        }
    }

    function showOrEdit() {
        if ("2" == taskFlag) {
            // 驳回呈报人
            $("#cltAuth").find(".isStlAmt").each(function (){
                $(this).addClass('Hide');
            });
            $("#cltAuth").find(".isResolve").each(function (){
                $(this).addClass('Hide');
            });
            $("#cltAuth").find(".btns").each(function (){
                $(this).addClass('Hide');
            });
        } else if ("1" == taskFlag || "3" == taskFlag || "4" == taskFlag || "5" == taskFlag) {
            // 渠道专员审批 || 渠道经理审批 || 信审员分解 || 更新回款异常
            liger.get("payer").setDisabled();
            liger.get("payDt").setDisabled();
            liger.get("recoveryAmt").setDisabled();
            liger.get("payWay").setDisabled();
            $("#cltAuth").find(".uploadFileDiv").each(function (){
                $(this).addClass('Hide');
            });
            if ("3" == taskFlag || "4" == taskFlag || "5" == taskFlag) {
                liger.get("isStlAmt").setDisabled(true);
                liger.get("isResolve").setDisabled(true);
                $("#cltAuth").find(".saveDiv").each(function (){
                    $(this).addClass('Hide');
                });
            }
        }
        if ("1" == viewFlag) {
            $("#cltAuth").find(".uploadFileDiv").each(function (){
                $(this).addClass('Hide');
            });
            $("#cltAuth").find(".saveDiv").each(function (){
                $(this).addClass('Hide');
            });
        }
    }

    //显示已上传但是未保存的文件列表
    function showFiles(data, index) {
        var applyNm = $("#uploadUsr").val();
        var applyDt = $("#applyDt").html();
        var f_Grid = liger.get("ligergrid_file" + index);
        var uploadJOSN = data;
        for (var i = 0; i < uploadJOSN.length; i++) {
            //添加行-追加行
            f_Grid.addRow({
                fileNm: uploadJOSN[i].fileNm,
                crtUsrRlNm: applyNm,
                crtTm: applyDt,
                doSthFlag: "1",
                ligerIndex: index
            });
        }
    }

</script>
</body>
</html>
